package com.zxkj.commonpatrol.adapt;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.tools.ActivityTool;
import com.daimajia.swipe.SwipeLayout;
import com.xuexiang.xui.widget.toast.XToast;
import com.zxkj.commonpatrol.R;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.response.InspectionDetailResponse;
import com.zxkj.commonpatrol.ui.AddCheckPointActivity;
import com.zxkj.commonpatrol.ui.CheckPointDetailActivity;

import java.util.List;

public class ProjectDetailAdapt extends BaseQuickAdapter<InspectionDetailResponse.InspectPoint, BaseViewHolder> {
    //路线COde
    private  String Code;

    public ProjectDetailAdapt(int layoutResId, @Nullable List<InspectionDetailResponse.InspectPoint> data,String Code) {
        super(layoutResId, data);
        this.Code=Code;
    }
    public MyProjectDetailCallBack mDataCallBack;

    //数据回调接口
    public interface MyProjectDetailCallBack<T> {
        void onDataSuccessCallBack( T t);
        void onDataFailCallBack(T t,T t1);
    }
    @Override
    protected void convert(BaseViewHolder helper, InspectionDetailResponse.InspectPoint item) {
        helper.setText(R.id.tv_upcoming_name, item.getName());
        helper.setText(R.id.tv_num, item.getNomalEventCount() + "/"+item.getEventTotal());
        helper.setText(R.id.tv_num2, item.getNomalDeviceCount() + "/"+item.getDeviceTotal());

        SwipeLayout swipeLayout= helper.itemView.findViewById(R.id.swipe);

        swipeLayout.setClickToClose(true);
        helper.setText(R.id.tv_address, item.getLocation());//項目編號
        Log.e("tv_address", item.getLocation() );
        helper.setText(R.id.tv_to_address, item.getLastUpdateDate());//位置

        TextView viewById = helper.itemView.findViewById(R.id.tv_upcoming_name);
        TextView viewById1 = helper.itemView.findViewById(R.id.tv_num);
        TextView viewById12 = helper.itemView.findViewById(R.id.tv_num2);
        if (item.getPointPatrolStatus()==0){
            viewById.setTextColor(getContext().getColor(R.color.red));
            viewById1.setTextColor(getContext().getColor(R.color.red));
            viewById12.setTextColor(getContext().getColor(R.color.red));
        }else{
            viewById.setTextColor(getContext().getColor(R.color.green));
            viewById1.setTextColor(getContext().getColor(R.color.green));
            viewById12.setTextColor(getContext().getColor(R.color.green));
        }






        helper.itemView.findViewById(R.id.rl_Delete).setOnClickListener(v -> {
            swipeLayout.close();
          mDataCallBack.onDataSuccessCallBack(helper.getLayoutPosition());
        });
        swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
            @Override
            public void onStartOpen(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(false);
            }

            @Override
            public void onOpen(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(false);
            }

            @Override
            public void onStartClose(SwipeLayout layout) {

            }

            @Override
            public void onClose(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(true);
            }

            @Override
            public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {

            }

            @Override
            public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {

            }
        });
        helper.itemView.findViewById(R.id.cl).setOnClickListener(v->{
            Intent intent =new Intent(getContext(), CheckPointDetailActivity.class);
            //
            intent.putExtra("Name",item.getName());
            intent.putExtra("RouteInspectNo",Code);
            intent.putExtra("PointNo",item.getCode());
            getContext().startActivity(intent);

     });


    }


    public void setmDataCallBack(MyProjectDetailCallBack mDataCallBack) {
        this.mDataCallBack = mDataCallBack;
    }
}